package concurrency;

import java.util.concurrent.locks.LockSupport;

/**
 * @Author DRevelation
 * @Date 2020-06-12 上午 9:48
 * @Desc
 */
public class LockSupportDemo {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("child thread begin park!");
                //调用park方法，挂起自己，只有线程被中断才会退出循环
                //如果不用中断，main线程用unpark也无法结束此线程
                while (!Thread.currentThread().isInterrupted()) {
                    LockSupport.park();
                }
                System.out.println("child thread unpark!");
            }
        });
        thread.start();

        Thread.sleep(1000);

        System.out.println("main thread begin unpark!");

//         LockSupport.unpark(thread);
        thread.interrupt();
    }
}
